#include "../../global/QmlNames.h"

#include "../RosterModel.h"
#include "GroupMemberModel.h"

X_BEGIN_NAMESPACE

GroupMemberModel::GroupMemberModel()
    : QObject(NULL)
    , d(new GroupMemberModelPrivate)
{
}

GroupMemberModel::GroupMemberModel(const QString bareJid)
    : QObject(NULL)
    , d(new GroupMemberModelPrivate)
{
    d->m_bareJid = bareJid;
}

GroupMemberModel::GroupMemberModel(const GroupMemberModel &src)
    : QObject(NULL)
    , d(src.d)
{

}

GroupMemberModel &GroupMemberModel::operator =(GroupMemberModel &rhs)
{
    if(this != &rhs) this->d = rhs.d;

    return *this;
}

const char *GroupMemberModel::qmlName()
{
    return QmlNames::SubModelType::GroupMemberModel;
}

GroupMemberModel &GroupMemberModel::setNickName(QString nickName)
{
    if (d->m_name == nickName)
        return *this;

    d->m_name = nickName;
    emit nickNameChanged(nickName);

    return *this;
}

GroupMemberModel& GroupMemberModel::setPhoto(QString photo)
{
    if (d->m_photo == photo)
        return *this;

    d->m_photo = photo;
    emit photoChanged(photo);

    return *this;
}

GroupMemberModel &GroupMemberModel::setAvailableStatus(AvailableStatus status)
{
    if (d->m_availableStatus == status)
        return *this;

    d->m_availableStatus = status;
    emit availableStatusChanged(status);

    return *this;
}

GroupMemberModel &GroupMemberModel::setPhotoType(PhotoType photoType)
{
    if (d->m_photoType == photoType)
        return *this;

    d->m_photoType = photoType;
    emit photoTypeChanged(photoType);

    return *this;
}

QString GroupMemberModel::bareJid() const
{
    return d->m_bareJid;
}

QString GroupMemberModel::nickName() const
{
    return d->m_name;
}

QString GroupMemberModel::photo() const
{
    return d->m_photo;
}

PhotoType GroupMemberModel::photoType() const
{
    return d->m_photoType;
}

AvailableStatus GroupMemberModel::availableStatus() const
{
    return d->m_availableStatus;
}

/**
 * @brief 当前成员与自己是否是好友。
 *
 * @return
 */
bool GroupMemberModel::isFriendWithMe() const
{
    return RosterModel::instance().findContact(d->m_bareJid) != NULL;
}

X_END_NAMESPACE
